package com.metaverse.backend.utils.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.math.BigInteger;
import java.time.LocalDate;

public class BigIntegerConverter implements Converter<BigInteger> {
    @Override
    public Class supportJavaTypeKey() {
        return BigInteger.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public BigInteger convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        try {
            return BigInteger.valueOf(Long.valueOf(cellData.getStringValue()));
        } catch (Exception e) {
        }
        return null;
    }

    @Override
    public CellData convertToExcelData(BigInteger bigInteger, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (bigInteger != null) {
            return new CellData(bigInteger.toString());
        }
        return null;
    }
}
